using System;
using Mbs.Modularity.AddIns;
using System.ComponentModel;
using Mbs.ComponentModel.Container;

namespace Mbs.Elements
{
    [Serializable]
    [Component(Id="Object",Service=typeof(IElementBuilder))]
    public class ObjectElementBuilder : ElementBuilder
    {

        public override object Create(object caller, IAddInItem element)
        {
            object obj = null;
            Type type = Type.GetType(element.Properties.Get<string>("Type"));
            if (type != null)
            {
                try
                {
                    obj = Activator.CreateInstance(type);
                }
                catch
                {
                    return null;
                }
            }
            return obj;
        }
    }
}
